/*
 * ResourceAnalysisUnit.h
 *
 *  Created on: Nov 17, 2008
 *      Author: Ryan
 */

#ifndef RESOURCEANALYSISUNIT_H_
#define RESOURCEANALYSISUNIT_H_

#include "Tools/WorkUnit.h"
#include "../../OOInterface/Objects/Point3.h"
#include "../../OOInterface/AIInterface.h"

typedef std::queue< OOInterface::Point3f > ResourceNodes;

class ResourceAnalysisUnit: public WorkUnit
{
public:
	ResourceAnalysisUnit( OOInterface::AIInterface* i , const OOInterface::Resource r, const OOInterface::Point3f loc, float searchRadius, ResourceNodes prevExtractors, float extractorRadius );
	virtual ~ResourceAnalysisUnit();

	void run();

	bool isDone() { return _isDone; }
	ResourceNodes getResult() { return _points; }

private:
	bool _isDone;
	OOInterface::AIInterface* _i;
	const OOInterface::Resource _resource;

	const OOInterface::Point3f _loc;
	float _searchRadius;
	ResourceNodes _oldExtractors;


	ResourceNodes _points;

	float _extractorRadius;



	void initializeMaps( float* valueMap, float* resourceMap );
	void findIdealLocations( const OOInterface::GameMap& map, float radius );
	void updateResourceMap( float* map, int width, int height, OOInterface::Point3f& p, float radius );
	void calculateValueLoc( float* map, float* valueLoc );
	void calculateValueLocAt( float* map, float* valueLoc, int x, int y );
	float findMaxNode( float* valueLoc, int& x, int& y, int width, int height );
};

#endif /* RESOURCEANALYSISUNIT_H_ */
